using System.Collections;
using System.Collections.Generic;
using System;
using Google.Protobuf;


public static class ServerMessageManager 
{
    static readonly Dictionary<int, Type> msgId2Type = new Dictionary<int, Type>();
    static readonly Dictionary<Type,int> msgType2Id = new Dictionary<Type, int>();
    static readonly Dictionary<int, System.Action<IMessage>> msgHandlers = new Dictionary<int, System.Action<IMessage>>();

    public static bool TryGetMsgId(Type type,out int msgId)
    {
        return msgType2Id.TryGetValue(type, out msgId);
    }

    public static bool TryGetMsgType(int msgId,out Type type)
    {
        return msgId2Type.TryGetValue(msgId, out type);
    }

    public static void RegistMessage(int id, Type type)
    {
        msgId2Type[id] = type;
        msgType2Id[type] = id;
    }

    public static void RegistNetEventHandler(int msgId, Action<IMessage> msgHandler)
    {
        msgHandlers[msgId] = msgHandler;
    }

    public static bool TryGetNetEventHandler(int msgId,out Action<IMessage> msgHandler)
    {
        return msgHandlers.TryGetValue(msgId, out msgHandler);
    }
}
